package primeNums;


import java.util.concurrent.CountDownLatch;

class Task implements Runnable {
    private int start;
    private boolean[] arr;
   // CountDownLatch count;

    Task(int start, boolean[] arr) {
        this.start = start;
        this.arr = arr;
    //    this.count = count;
    }

    @Override
    public void run() {
        for (int i = start; i < arr.length && !arr[i]; i++){
            if (i%2==0) arr[i] = true;
        }

        for (int i = start; !arr[i] && i < arr.length; i++) {
            if (i%3==0) arr[i] = true;
        }

        for (int i = start; !arr[i] && i < arr.length; i++) {
            if (i%5==0) arr[i] = true;
        }

        for (int i = start; !arr[i] && i < arr.length; i++) {
            if (i%7==0) arr[i] = true;
        }

        for (int i = start; i < arr.length/2+1; i++) {
            if (!arr[i]) {
                for (int j = 2 * i; j < arr.length && !arr[j]; j += i) {
                    arr[j] = true;
                }
            }
        }
        Prime.count.countDown();
    }
}
